package com.heima.article.listen;


import com.heima.article.service.ApArticleService;
import com.heima.common.constants.message.PublishArticleConstants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
@Slf4j
public class publishArticle {

    @Autowired
    ApArticleService apArticleService;
    @RabbitListener(queuesToDeclare = @Queue(PublishArticleConstants.PUBLISH_ARTICLE_QUEUE))
    public void listenPublishArticle(String newsId){
        log.info("接收到文章发布消息，消息的内容为 ：{} , 接收消息的时间：{}" , newsId ,
                LocalDateTime.now().toString());
        apArticleService.publishArticle(Integer.valueOf(newsId));
        log.info("文章发布结束");

    }
}
